%     AERO LOAD - программа для нагружения агрегатов самолета распределенной нагрузкой
%     Copyright (C) 2018-2024  Михаил Козлов
%     Сайт проекта: <http://www.fastenerdoctor.ru/>
%     Адрес электронной почты для связи с разработчиком:
%     <doctor.fastener@gmail.com>
% 
%     Эта программа является свободным программным обеспечением: Вы можете
%     распространять ее и/или изменять, соблюдая условия Универсальной общественной
%     лицензии GNU, опубликованной Фондом свободного программного обеспечения,
%     либо редакции 3, либо (на Ваше усмотрение) любой редакции, выпущенной позже.
% 
%     Эта программа распространяется в надежде на то, что она окажется полезной,
%     но БЕЗ КАКИХ-ЛИБО ГАРАНТИЙ, включая даже подразумеваемую гарантию ТОВАРНОЙ ПРИГОДНОСТИ,
%     либо ПРИГОДНОСТИ ДЛЯ ОПРЕДЕЛЕННЫХ ЦЕЛЕЙ. Ознакомьтесь с Универсальной общественной
%     лицензией GNU для получения более подробной информации.
% 
%     Вы должны были получить копию Универсальной общественной лицензии GNU
%     вместе с этой программой. Если Вы ее не получили, то перейдите по адресу:
%     <http://www.gnu.org/licenses/>.
% 
%     This program is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     (at your option) any later version.
% 
%     This program is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%     GNU General Public License for more details.
% 
%     You should have received a copy of the GNU General Public License
%     along with this program.  If not, see <https://www.gnu.org/licenses/>.

function GW_Plot_Erase_Diagrams(src,~)

global Graphic_Window_Handle;
global Graphics_Properties;
global Graphics;

Axes_Handle = findall(Graphic_Window_Handle, 'Tag', 'Main_Axes');

switch src.Tag
    
    case 'Plot_Diagrams_Button'
        
        % Erase
        tmp.Value = 1;
        tmp.Tag = 'Erase_Diagrams_Button';
        GW_Plot_Erase_Diagrams(tmp,[]);
        
        % Теоретический центр давления
        Button_Handle = findall(Graphic_Window_Handle, 'Tag', 'Draw_Pressure_Center_Button');
        if (strcmp(Button_Handle.Enable, 'on'))
            tmp.Value = 1;
            tmp.Tag = 'Draw_Pressure_Center_Button';
            GW_Plot_Erase_Diagrams(tmp,[]);
            set(findall(Graphic_Window_Handle, 'Tag', tmp.Tag), 'Value', 1);
        end
        
    case 'Erase_Diagrams_Button'
        
        tmp.Value = 0;
        tmp.Tag = 'Draw_Span_Load_Diag_Button';
        GW_Plot_Erase_Diagrams(tmp,[]);
        set(findall(Graphic_Window_Handle, 'Tag', tmp.Tag), 'Value', 0);
        
        tmp.Value = 0;
        tmp.Tag = 'Draw_Pressure_Diag_Button';
        GW_Plot_Erase_Diagrams(tmp,[]);
        set(findall(Graphic_Window_Handle, 'Tag', tmp.Tag), 'Value', 0);
        
        tmp.Value = 0;
        tmp.Tag = 'Draw_Pressure_Center_Button';
        GW_Plot_Erase_Diagrams(tmp,[]);
        set(findall(Graphic_Window_Handle, 'Tag', tmp.Tag), 'Value', 0);
        
        tmp.Value = 0;
        tmp.Tag = 'Draw_Pressure_Centers_Line_Button';
        GW_Plot_Erase_Diagrams(tmp,[]);
        set(findall(Graphic_Window_Handle, 'Tag', tmp.Tag), 'Value', 0);
        
    case 'Draw_Span_Load_Diag_Button'
        
        Slider_Handle = findall(Graphic_Window_Handle, 'Tag', 'Span_Load_Diag_Translucency_Slider');
        
        if (src.Value == 1)
            
            N_Points = Graphics_Properties.Span_Load_Diag_N_Points;

            Load_Values = zeros(N_Points,1);
            Load_Diag = zeros(N_Points,3);

            Max_Load = 0;

            for i=1:N_Points

                ksi = (i-1)/(N_Points-1);

                Load_Diag(i,:) = (Graphics.Load.Chord_Surface.A1_projected * (1 - ksi) + Graphics.Load.Chord_Surface.A2_projected * ksi)';

                % Вычисление погонной нагрузки
                switch Graphics.Load.Span_Load.Law

                    case {'TRAPEZOID', 'CHORD_PROPORTIONAL'}

                        Linear_Load = (Graphics.Load.Precomputed_Data.Linear_Load_Root - Graphics.Load.Precomputed_Data.Linear_Load_Difference * ksi) * Graphics.Load.Correction_Coefficient;

                    case 'LOAD_DIAGRAM'

                        Linear_Load = Access_Array(Graphics.Load.Span_Load.Load_Diagram_Data, ksi*Graphics.Load.Precomputed_Data.Span_Length, ...
                                                           Graphics.Load.Extrapolation.Span_Load_0, Graphics.Load.Extrapolation.Span_Load_1) * Graphics.Load.Correction_Coefficient;

                end

                Load_Values(i) = Linear_Load;

                if (abs(Linear_Load) > Max_Load)
                    Max_Load = abs(Linear_Load);
                end

            end

            Load_Values = Load_Values / Max_Load;

            for i=1:N_Points

                Load_Diag(i,:) = Load_Diag(i,:) + Graphics.Load.Vector' * Load_Values(i) * Graphics.Span_Load_Diag_Length;

            end

            Load_Diag_Boundary = zeros(4,3);
            Load_Diag_Boundary(1,:) = Load_Diag(1,:);
            Load_Diag_Boundary(2,:) = Graphics.Load.Chord_Surface.A1_projected';
            Load_Diag_Boundary(3,:) = Graphics.Load.Chord_Surface.A2_projected';
            Load_Diag_Boundary(4,:) = Load_Diag(N_Points,:);
            
            Span_Load_Diag_Vertices = [Graphics.Load.Chord_Surface.A1_projected'; Load_Diag; Graphics.Load.Chord_Surface.A2_projected'];
            Span_Load_Diag_Faces = linspace(1, N_Points+2, N_Points+2);
            
            patch(Axes_Handle, 'Vertices', Span_Load_Diag_Vertices, ...
                               'Faces', Span_Load_Diag_Faces, ...
                               'FaceColor', Graphics_Properties.Span_Load_Diag_Color, ...
                               'EdgeColor', 'none', ...
                               'FaceAlpha', Slider_Handle.Value, ...
                               'Tag', 'Span_Load_Diag_Surface');
            
            Span_Load_Diag_Boundary = plot3(Axes_Handle, Load_Diag_Boundary(:,1), Load_Diag_Boundary(:,2), Load_Diag_Boundary(:,3));

            set(Span_Load_Diag_Boundary, 'Color', Graphics_Properties.Span_Load_Diag_Color);
            set(Span_Load_Diag_Boundary, 'LineWidth', Graphics_Properties.Span_Load_Diag_Boundary_Width);
            set(Span_Load_Diag_Boundary, 'Tag', 'Span_Load_Diag_Boundary');

            Span_Load_Diag = plot3(Axes_Handle, Load_Diag(:,1), Load_Diag(:,2), Load_Diag(:,3));

            set(Span_Load_Diag, 'Color', Graphics_Properties.Span_Load_Diag_Color);
            set(Span_Load_Diag, 'LineWidth', Graphics_Properties.Span_Load_Diag_Width);
            set(Span_Load_Diag, 'Tag', 'Span_Load_Diag');
            
            % Активировать кнопку
            set(findall(Graphic_Window_Handle, 'Tag', 'Span_Load_Diag_Translucency_Slider'), 'Enable', 'on');
            set(findall(Graphic_Window_Handle, 'Tag', 'Span_Load_Diag_Translucency_Text'), 'Enable', 'on');
            
        else
            
            % Деактивировать кнопку
            set(findall(Graphic_Window_Handle, 'Tag', 'Span_Load_Diag_Translucency_Slider'), 'Enable', 'off');
            set(findall(Graphic_Window_Handle, 'Tag', 'Span_Load_Diag_Translucency_Text'), 'Enable', 'off');
            
            delete(findall(Graphic_Window_Handle, 'Tag', 'Span_Load_Diag_Surface'));
            delete(findall(Graphic_Window_Handle, 'Tag', 'Span_Load_Diag_Boundary'));
            delete(findall(Graphic_Window_Handle, 'Tag', 'Span_Load_Diag'));
            
        end
        
    case 'Span_Load_Diag_Translucency_Slider'
        
        set(findall(Graphic_Window_Handle, 'Tag', 'Span_Load_Diag_Surface'), 'FaceAlpha', src.Value);
        set(findall(Graphic_Window_Handle, 'Tag', 'Span_Load_Diag_Translucency_Text'), 'String', sprintf('%.2f', src.Value));
        
    case 'Draw_Pressure_Diag_Button'
        
        Slider_Handle = findall(Graphic_Window_Handle, 'Tag', 'Pressure_Diag_Translucency_Slider');
        
        if (src.Value == 1)
            
            N_Diag = Graphics_Properties.Pressure_Diag_Number;
            N_Points = Graphics_Properties.Pressure_Diag_N_Points;
            
            Pressure_Diag = cell(N_Diag,1);
            
            Pressure_Values = zeros(N_Diag,N_Points);
            Max_Pressure = 0;
            
            for i=1:N_Diag
                
                Pressure_Diag{i}.Data = zeros(N_Points,3);
                
                ksi = (i-1)/(N_Diag-1);
                
                for j=1:N_Points
                    
                    etta = (j-1)/(N_Points-1);
                    
                    Pressure_Diag{i}.Data(j,:) = Get_Cartesian_Coord(Graphics.Load.Chord_Surface.A1_projected, Graphics.Load.Chord_Surface.A2_projected, ...
                                                                     Graphics.Load.Chord_Surface.A3_projected, Graphics.Load.Chord_Surface.A4_projected, ksi, etta)';
                    
                    Current_Pressure = Pressure(Graphics.Load, ksi, etta);
                    
                    Pressure_Values(i,j) = Current_Pressure;
                    
                    if (abs(Current_Pressure) > Max_Pressure)
                        Max_Pressure = abs(Current_Pressure);
                    end
                    
                end
                
            end
            
            Pressure_Values = Pressure_Values / Max_Pressure;

            for i=1:N_Diag
                
                for j=1:N_Points

                    Pressure_Diag{i}.Data(j,:) = Pressure_Diag{i}.Data(j,:) + Graphics.Load.Vector' * Pressure_Values(i,j) * Graphics.Pressure_Diag_Length;
                
                end

            end
            
            for i=1:N_Diag
                
                ksi = (i-1)/(N_Diag-1);
                
                Pressure_Diag{i}.Boundary = zeros(4,3);
                
                Pressure_Diag{i}.Boundary(1,:) = Pressure_Diag{i}.Data(1,:);
                Pressure_Diag{i}.Boundary(2,:) = Get_Cartesian_Coord(Graphics.Load.Chord_Surface.A1_projected, Graphics.Load.Chord_Surface.A2_projected, ...
                                                                     Graphics.Load.Chord_Surface.A3_projected, Graphics.Load.Chord_Surface.A4_projected, ksi, 0)';
                Pressure_Diag{i}.Boundary(3,:) = Get_Cartesian_Coord(Graphics.Load.Chord_Surface.A1_projected, Graphics.Load.Chord_Surface.A2_projected, ...
                                                                     Graphics.Load.Chord_Surface.A3_projected, Graphics.Load.Chord_Surface.A4_projected, ksi, 1)';
                Pressure_Diag{i}.Boundary(4,:) = Pressure_Diag{i}.Data(N_Points,:);
                
                Pressure_Diag{i}.Vertices = [Pressure_Diag{i}.Boundary(2,:); Pressure_Diag{i}.Data; Pressure_Diag{i}.Boundary(3,:)];
                Pressure_Diag{i}.Faces = linspace(1, N_Points+2, N_Points+2);
                
            end
            
            for i=1:N_Diag
                
                patch(Axes_Handle, 'Vertices', Pressure_Diag{i}.Vertices, ...
                                   'Faces', Pressure_Diag{i}.Faces, ...
                                   'FaceColor', Graphics_Properties.Pressure_Diag_Color, ...
                                   'EdgeColor', 'none', ...
                                   'FaceAlpha', Slider_Handle.Value, ...
                                   'Tag', 'Pressure_Diag_Surface');
                
                Pressure_Diag_Boundary = plot3(Axes_Handle, Pressure_Diag{i}.Boundary(:,1), Pressure_Diag{i}.Boundary(:,2), Pressure_Diag{i}.Boundary(:,3));
                
                set(Pressure_Diag_Boundary, 'Color', Graphics_Properties.Pressure_Diag_Color);
                set(Pressure_Diag_Boundary, 'LineWidth', Graphics_Properties.Pressure_Diag_Boundary_Width);
                set(Pressure_Diag_Boundary, 'Tag', 'Pressure_Diag_Boundary');
                
                Pressure_Diag_Handle = plot3(Axes_Handle, Pressure_Diag{i}.Data(:,1), Pressure_Diag{i}.Data(:,2), Pressure_Diag{i}.Data(:,3));

                set(Pressure_Diag_Handle, 'Color', Graphics_Properties.Pressure_Diag_Color);
                set(Pressure_Diag_Handle, 'LineWidth', Graphics_Properties.Pressure_Diag_Width);
                set(Pressure_Diag_Handle, 'Tag', 'Pressure_Diag');
                
            end
            
            % Активировать кнопку
            set(findall(Graphic_Window_Handle, 'Tag', 'Pressure_Diag_Translucency_Slider'), 'Enable', 'on');
            set(findall(Graphic_Window_Handle, 'Tag', 'Pressure_Diag_Translucency_Text'), 'Enable', 'on');
            set(findall(Graphic_Window_Handle, 'Tag', 'Pressure_Diag_Minus'), 'Enable', 'on');
            set(findall(Graphic_Window_Handle, 'Tag', 'Pressure_Diag_Plus'), 'Enable', 'on');
            set(findall(Graphic_Window_Handle, 'Tag', 'Pressure_Diag_Number'), 'Enable', 'on');
            
        else
            
            % Деактивировать кнопку
            set(findall(Graphic_Window_Handle, 'Tag', 'Pressure_Diag_Translucency_Slider'), 'Enable', 'off');
            set(findall(Graphic_Window_Handle, 'Tag', 'Pressure_Diag_Translucency_Text'), 'Enable', 'off');
            set(findall(Graphic_Window_Handle, 'Tag', 'Pressure_Diag_Minus'), 'Enable', 'off');
            set(findall(Graphic_Window_Handle, 'Tag', 'Pressure_Diag_Plus'), 'Enable', 'off');
            set(findall(Graphic_Window_Handle, 'Tag', 'Pressure_Diag_Number'), 'Enable', 'off');
            
            delete(findall(Graphic_Window_Handle, 'Tag', 'Pressure_Diag_Surface'));
            delete(findall(Graphic_Window_Handle, 'Tag', 'Pressure_Diag_Boundary'));
            delete(findall(Graphic_Window_Handle, 'Tag', 'Pressure_Diag'));
            
        end
        
    case 'Pressure_Diag_Minus'
        
        Graphics_Properties.Pressure_Diag_Number = Graphics_Properties.Pressure_Diag_Number - 1;
        
        if (Graphics_Properties.Pressure_Diag_Number < 2)
            
            Graphics_Properties.Pressure_Diag_Number = 2;
            
        else
            
            tmp.Value = 0;
            tmp.Tag = 'Draw_Pressure_Diag_Button';
            GW_Plot_Erase_Diagrams(tmp,[]);
            
            tmp.Value = 1;
            tmp.Tag = 'Draw_Pressure_Diag_Button';
            GW_Plot_Erase_Diagrams(tmp,[]);
            
        end
        
        set(findall(Graphic_Window_Handle, 'Tag', 'Pressure_Diag_Number'), 'String', sprintf('%i', Graphics_Properties.Pressure_Diag_Number));
        
    case 'Pressure_Diag_Plus'
        
        Graphics_Properties.Pressure_Diag_Number = Graphics_Properties.Pressure_Diag_Number + 1;
        
        if (Graphics_Properties.Pressure_Diag_Number > 99)
            
            Graphics_Properties.Pressure_Diag_Number = 99;
            
        else
            
            tmp.Value = 0;
            tmp.Tag = 'Draw_Pressure_Diag_Button';
            GW_Plot_Erase_Diagrams(tmp,[]);
            
            tmp.Value = 1;
            tmp.Tag = 'Draw_Pressure_Diag_Button';
            GW_Plot_Erase_Diagrams(tmp,[]);
            
        end
        
        set(findall(Graphic_Window_Handle, 'Tag', 'Pressure_Diag_Number'), 'String', sprintf('%i', Graphics_Properties.Pressure_Diag_Number));
        
    case 'Pressure_Diag_Translucency_Slider'
        
        set(findall(Graphic_Window_Handle, 'Tag', 'Pressure_Diag_Surface'), 'FaceAlpha', src.Value);
        set(findall(Graphic_Window_Handle, 'Tag', 'Pressure_Diag_Translucency_Text'), 'String', sprintf('%.2f', src.Value));
    
    case 'Draw_Pressure_Center_Button'
        
        if (src.Value == 1)
            
            Data = nan(12,3);
            
            Tmp_Vector_1 = Graphics.Load.Chord_Surface.A1_projected - Graphics.Load.Chord_Surface.A2_projected;
            Tmp_Vector_1 = Tmp_Vector_1/norm(Tmp_Vector_1);
            
            Tmp_Vector_2 = cross(Tmp_Vector_1, Graphics.Load.Vector);
            Tmp_Vector_2 = Tmp_Vector_2/norm(Tmp_Vector_2);
            
            Data(1,:) = Graphics.Load_Summary.Pressure_Center_XYZ_Projected;
            Data(2,:) = Graphics.Load_Summary.Pressure_Center_XYZ_Projected + Tmp_Vector_1*Graphics.Pressure_Center_Width/2;
            Data(4,:) = Graphics.Load_Summary.Pressure_Center_XYZ_Projected;
            Data(5,:) = Graphics.Load_Summary.Pressure_Center_XYZ_Projected - Tmp_Vector_1*Graphics.Pressure_Center_Width/2;
            Data(7,:) = Graphics.Load_Summary.Pressure_Center_XYZ_Projected;
            Data(8,:) = Graphics.Load_Summary.Pressure_Center_XYZ_Projected + Tmp_Vector_2*Graphics.Pressure_Center_Width/2;
            Data(10,:) = Graphics.Load_Summary.Pressure_Center_XYZ_Projected;
            Data(11,:) = Graphics.Load_Summary.Pressure_Center_XYZ_Projected - Tmp_Vector_2*Graphics.Pressure_Center_Width/2;

            Pressure_Center_Handle = plot3(Axes_Handle, Data(:,1), Data(:,2), Data(:,3));
            
            set(Pressure_Center_Handle, 'Color', Graphics_Properties.Pressure_Center_Color);
            set(Pressure_Center_Handle, 'LineWidth', Graphics_Properties.Pressure_Center_Line_Width);
            set(Pressure_Center_Handle, 'Tag', 'Pressure_Center');
            
            % Активировать кнопку
            set(findall(Graphic_Window_Handle, 'Tag', 'Label_Pressure_Center_Button'), 'Enable', 'on');
            
        else
            
            % Удалить данные и деактивировать кнопку
            tmp.Value = 0;
            tmp.Tag = 'Label_Pressure_Center_Button';
            GW_Plot_Erase_Diagrams(tmp,[]);
            set(findall(Graphic_Window_Handle, 'Tag', tmp.Tag), 'Value', 0, 'Enable', 'off');
            
            delete(findall(Graphic_Window_Handle, 'Tag', 'Pressure_Center'));
            
        end
        
    case 'Label_Pressure_Center_Button'
        
        if (src.Value == 1)
            
            if (isequal(get(Graphic_Window_Handle, 'Color'), [0 0 0]))
                Color = 'white';
            else
                Color = 'black';
            end
            
            switch Graphics_Properties.Language
                case 'RU'
                    
                    switch Graphics.Load.Distributed_Load_Mode
                        case 'CID_DISTR_LOAD'
                            string = '       Теоретический центр давления';
                        case 'PRESSURE'
                            string = '       Теоретический центр давления (Pn)';
                    end
                    
                case 'EN'
                    
                    switch Graphics.Load.Distributed_Load_Mode
                        case 'CID_DISTR_LOAD'
                            string = '       Theoretical pressure center';
                        case 'PRESSURE'
                            string = '       Theoretical Pn pressure center';
                    end
                    
            end
            
            Label_Handle = text(Axes_Handle, Graphics.Load_Summary.Pressure_Center_XYZ_Projected(1), Graphics.Load_Summary.Pressure_Center_XYZ_Projected(2), ...
                                             Graphics.Load_Summary.Pressure_Center_XYZ_Projected(3), string);
            set(Label_Handle, 'Color', Color, 'Tag', 'Pressure_Center_Label');
            
            % Активировать кнопку
            set(findall(Graphic_Window_Handle, 'Tag', 'Pressure_Center_Coord_Button'), 'Enable', 'on');
            set(findall(Graphic_Window_Handle, 'Tag', 'Pressure_Center_Param_Coord_Button'), 'Enable', 'on');
            
        else
            
            % Удалить данные и деактивировать кнопку
            tmp.Value = 0;
            tmp.Tag = 'Pressure_Center_Coord_Button';
            GW_Plot_Erase_Diagrams(tmp,[]);
            set(findall(Graphic_Window_Handle, 'Tag', tmp.Tag), 'Value', 0, 'Enable', 'off');
            
            % Удалить данные и деактивировать кнопку
            tmp.Value = 0;
            tmp.Tag = 'Pressure_Center_Param_Coord_Button';
            GW_Plot_Erase_Diagrams(tmp,[]);
            set(findall(Graphic_Window_Handle, 'Tag', tmp.Tag), 'Value', 0, 'Enable', 'off');
            
            delete(findall(Graphic_Window_Handle, 'Tag', 'Pressure_Center_Label'));
            
        end
        
    case 'Pressure_Center_Coord_Button'
        
        if (src.Value == 1)
            
            handle = findall(Graphic_Window_Handle, 'Tag', 'Pressure_Center_Label');
            
            handle_2 = findall(Graphic_Window_Handle, 'Tag', 'Pressure_Center_Param_Coord_Button');
            
            if (~isempty(handle))
                
                if (handle_2.Value == 0)
                    
                    handle.String = [handle.String sprintf('   [%g, %g, %g]', Graphics.Load_Summary.Pressure_Center_XYZ_Projected(1), Graphics.Load_Summary.Pressure_Center_XYZ_Projected(2), ...
                                                                              Graphics.Load_Summary.Pressure_Center_XYZ_Projected(3))];
                    
                else
                    
                    switch Graphics_Properties.Language
                        case 'RU'

                            switch Graphics.Load.Distributed_Load_Mode
                                case 'CID_DISTR_LOAD'
                                    str_len = 35;
                                case 'PRESSURE'
                                    str_len = 40;
                            end

                        case 'EN'

                            switch Graphics.Load.Distributed_Load_Mode
                                case 'CID_DISTR_LOAD'
                                    str_len = 34;
                                case 'PRESSURE'
                                    str_len = 37;
                            end

                    end
                    
                    handle.String = handle.String(1:str_len);
                    handle.String = [handle.String sprintf('   [%g, %g, %g]', Graphics.Load_Summary.Pressure_Center_XYZ_Projected(1), Graphics.Load_Summary.Pressure_Center_XYZ_Projected(2), ...
                                                                              Graphics.Load_Summary.Pressure_Center_XYZ_Projected(3))];
                                                                          
                    tmp.Value = 1;
                    tmp.Tag = 'Pressure_Center_Param_Coord_Button';
                    GW_Plot_Erase_Diagrams(tmp,[]);
                    
                end

            end
            
        else
            
            switch Graphics_Properties.Language
                case 'RU'
                    
                    switch Graphics.Load.Distributed_Load_Mode
                        case 'CID_DISTR_LOAD'
                            str_len = 35;
                        case 'PRESSURE'
                            str_len = 40;
                    end
                    
                case 'EN'
                    
                    switch Graphics.Load.Distributed_Load_Mode
                        case 'CID_DISTR_LOAD'
                            str_len = 34;
                        case 'PRESSURE'
                            str_len = 37;
                    end
                    
            end
            
            handle = findall(Graphic_Window_Handle, 'Tag', 'Pressure_Center_Label');
            if (~isempty(handle))
                handle.String = handle.String(1:str_len);
            end
            
            handle = findall(Graphic_Window_Handle, 'Tag', 'Pressure_Center_Param_Coord_Button');
            
            if (handle.Value == 1)
                tmp.Value = 1;
                tmp.Tag = 'Pressure_Center_Param_Coord_Button';
                GW_Plot_Erase_Diagrams(tmp,[]);
            end
            
        end
        
    case 'Pressure_Center_Param_Coord_Button'
        
        if (src.Value == 1)
            
            handle = findall(Graphic_Window_Handle, 'Tag', 'Pressure_Center_Label');
            if (~isempty(handle))
                handle.String = [handle.String sprintf('   [%g, %g]', Graphics.Load_Summary.Pressure_Center_ksi, Graphics.Load_Summary.Pressure_Center_etta)];
            end
            
        else
            
            switch Graphics_Properties.Language
                case 'RU'
                    
                    switch Graphics.Load.Distributed_Load_Mode
                        case 'CID_DISTR_LOAD'
                            str_len = 35;
                        case 'PRESSURE'
                            str_len = 40;
                    end
                    
                case 'EN'
                    
                    switch Graphics.Load.Distributed_Load_Mode
                        case 'CID_DISTR_LOAD'
                            str_len = 34;
                        case 'PRESSURE'
                            str_len = 37;
                    end
                    
            end
            
            handle = findall(Graphic_Window_Handle, 'Tag', 'Pressure_Center_Label');
            if (~isempty(handle))
                handle.String = handle.String(1:str_len);
            end
            
            handle = findall(Graphic_Window_Handle, 'Tag', 'Pressure_Center_Coord_Button');
            
            if (handle.Value == 1)
                tmp.Value = 1;
                tmp.Tag = 'Pressure_Center_Coord_Button';
                GW_Plot_Erase_Diagrams(tmp,[]);
            end
            
        end
        
    case 'Draw_Pressure_Centers_Line_Button'
        
        if (src.Value == 1)
            
            if (~isempty(Graphics.Load.Precomputed_Data.Chord_Pressure_Center))

                Xd_Plot = zeros(2,3);

                Xd_Plot(1,:) = (Graphics.Load.Chord_Surface.A1_projected + (Graphics.Load.Chord_Surface.A3_projected - Graphics.Load.Chord_Surface.A1_projected) * Graphics.Load.Precomputed_Data.Chord_Pressure_Center)';
                Xd_Plot(2,:) = (Graphics.Load.Chord_Surface.A2_projected + (Graphics.Load.Chord_Surface.A4_projected - Graphics.Load.Chord_Surface.A2_projected) * Graphics.Load.Precomputed_Data.Chord_Pressure_Center)';

            else

                Mandatory_Points = [];

                switch Graphics.Load.Chord_Pressure.Law

                    case 'TRAPEZOID'

                        if (strcmp(Graphics.Load.Chord_Pressure.Trapezoid_Xd_Type, 'DISTRIBUTION'))
                            Mandatory_Points = Union_Column(Mandatory_Points, Graphics.Load.Chord_Pressure.Trapezoid_Xd_Distr_Data(:,1));
                        end

                    case {'MODEL_1', 'MODEL_3', 'MODEL_15'}

                        if (strcmp(Graphics.Load.Chord_Pressure.Model_X_p2_p1_Type, 'DISTRIBUTION'))
                            Mandatory_Points = Union_Column(Mandatory_Points, Graphics.Load.Chord_Pressure.Model_X_p2_p1_Distr_Data(:,1));
                        end

                        if (strcmp(Graphics.Load.Chord_Pressure.Model_X_f_Type, 'DISTRIBUTION'))
                            Mandatory_Points = Union_Column(Mandatory_Points, Graphics.Load.Chord_Pressure.Model_X_f_Distr_Data(:,1));
                        end

                    case 'MODEL_2'

                        if (strcmp(Graphics.Load.Chord_Pressure.Model_X_p2_p1_Type, 'DISTRIBUTION'))
                            Mandatory_Points = Union_Column(Mandatory_Points, Graphics.Load.Chord_Pressure.Model_X_p2_p1_Distr_Data(:,1));
                        end

                        if (strcmp(Graphics.Load.Chord_Pressure.Model_X_p3_p1_Type, 'DISTRIBUTION'))
                            Mandatory_Points = Union_Column(Mandatory_Points, Graphics.Load.Chord_Pressure.Model_X_p3_p1_Distr_Data(:,1));
                        end

                        if (strcmp(Graphics.Load.Chord_Pressure.Model_X_f_Type, 'DISTRIBUTION'))
                            Mandatory_Points = Union_Column(Mandatory_Points, Graphics.Load.Chord_Pressure.Model_X_f_Distr_Data(:,1));
                        end

                    case {'MODEL_4', 'MODEL_10'}

                        if (strcmp(Graphics.Load.Chord_Pressure.Model_X_f_Type, 'DISTRIBUTION'))
                            Mandatory_Points = Union_Column(Mandatory_Points, Graphics.Load.Chord_Pressure.Model_X_f_Distr_Data(:,1));
                        end

                    case 'MODEL_5'

                        % Ничего не делаем

                    case {'MODEL_6', 'MODEL_8', 'MODEL_14'}

                        if (strcmp(Graphics.Load.Chord_Pressure.Model_X_p2_p1_Type, 'DISTRIBUTION'))
                            Mandatory_Points = Union_Column(Mandatory_Points, Graphics.Load.Chord_Pressure.Model_X_p2_p1_Distr_Data(:,1));
                        end

                        if (strcmp(Graphics.Load.Chord_Pressure.Model_X_f1_Type, 'DISTRIBUTION'))
                            Mandatory_Points = Union_Column(Mandatory_Points, Graphics.Load.Chord_Pressure.Model_X_f1_Distr_Data(:,1));
                        end

                        if (strcmp(Graphics.Load.Chord_Pressure.Model_X_f2_Type, 'DISTRIBUTION'))
                            Mandatory_Points = Union_Column(Mandatory_Points, Graphics.Load.Chord_Pressure.Model_X_f2_Distr_Data(:,1));
                        end

                    case {'MODEL_7', 'MODEL_11', 'MODEL_13'}

                        if (strcmp(Graphics.Load.Chord_Pressure.Model_X_p2_p1_Type, 'DISTRIBUTION'))
                            Mandatory_Points = Union_Column(Mandatory_Points, Graphics.Load.Chord_Pressure.Model_X_p2_p1_Distr_Data(:,1));
                        end

                        if (strcmp(Graphics.Load.Chord_Pressure.Model_X_p3_p1_Type, 'DISTRIBUTION'))
                            Mandatory_Points = Union_Column(Mandatory_Points, Graphics.Load.Chord_Pressure.Model_X_p3_p1_Distr_Data(:,1));
                        end

                        if (strcmp(Graphics.Load.Chord_Pressure.Model_X_f1_Type, 'DISTRIBUTION'))
                            Mandatory_Points = Union_Column(Mandatory_Points, Graphics.Load.Chord_Pressure.Model_X_f1_Distr_Data(:,1));
                        end

                        if (strcmp(Graphics.Load.Chord_Pressure.Model_X_f2_Type, 'DISTRIBUTION'))
                            Mandatory_Points = Union_Column(Mandatory_Points, Graphics.Load.Chord_Pressure.Model_X_f2_Distr_Data(:,1));
                        end

                    case 'MODEL_9'

                        if (strcmp(Graphics.Load.Chord_Pressure.Model_X_f1_Type, 'DISTRIBUTION'))
                            Mandatory_Points = Union_Column(Mandatory_Points, Graphics.Load.Chord_Pressure.Model_X_f1_Distr_Data(:,1));
                        end

                        if (strcmp(Graphics.Load.Chord_Pressure.Model_X_f2_Type, 'DISTRIBUTION'))
                            Mandatory_Points = Union_Column(Mandatory_Points, Graphics.Load.Chord_Pressure.Model_X_f2_Distr_Data(:,1));
                        end

                    case 'MODEL_12'

                        if (strcmp(Graphics.Load.Chord_Pressure.Model_X_p2_p1_Type, 'DISTRIBUTION'))
                            Mandatory_Points = Union_Column(Mandatory_Points, Graphics.Load.Chord_Pressure.Model_X_p2_p1_Distr_Data(:,1));
                        end

                        if (strcmp(Graphics.Load.Chord_Pressure.Model_X_p3_p1_Type, 'DISTRIBUTION'))
                            Mandatory_Points = Union_Column(Mandatory_Points, Graphics.Load.Chord_Pressure.Model_X_p3_p1_Distr_Data(:,1));
                        end

                        if (strcmp(Graphics.Load.Chord_Pressure.Model_X_p4_p1_Type, 'DISTRIBUTION'))
                            Mandatory_Points = Union_Column(Mandatory_Points, Graphics.Load.Chord_Pressure.Model_X_p4_p1_Distr_Data(:,1));
                        end

                        if (strcmp(Graphics.Load.Chord_Pressure.Model_X_f1_Type, 'DISTRIBUTION'))
                            Mandatory_Points = Union_Column(Mandatory_Points, Graphics.Load.Chord_Pressure.Model_X_f1_Distr_Data(:,1));
                        end

                        if (strcmp(Graphics.Load.Chord_Pressure.Model_X_f2_Type, 'DISTRIBUTION'))
                            Mandatory_Points = Union_Column(Mandatory_Points, Graphics.Load.Chord_Pressure.Model_X_f2_Distr_Data(:,1));
                        end

                    case 'USER_MODEL'

                        Mandatory_Points = Union_Column(Mandatory_Points, Graphics.Load.Chord_Pressure.User_Model_Data.Span_Coord);

                end

                Points = Union_Column(linspace(0,1,200)', Mandatory_Points);

                Xd_Plot = zeros(size(Points,1),3);

                switch Graphics.Load.Chord_Pressure.Law

                    case 'TRAPEZOID'

                        for i=1:size(Points,1)

                            k = Access_Array(Graphics.Load.Chord_Pressure.Trapezoid_Xd_Distr_Data, Points(i), Graphics.Load.Extrapolation.Trapezoid_Xd_0, Graphics.Load.Extrapolation.Trapezoid_Xd_1);

                            P1 = Graphics.Load.Chord_Surface.A1_projected * (1 - Points(i)) + Graphics.Load.Chord_Surface.A2_projected * Points(i);
                            P2 = Graphics.Load.Chord_Surface.A3_projected * (1 - Points(i)) + Graphics.Load.Chord_Surface.A4_projected * Points(i);

                            Xd_Plot(i,:) = (P1 * (1 - k) + P2 * k)';

                        end

                    case 'USER_MODEL'

                        for i=1:size(Points,1)

                            k = Center_Of_Mass(Access_User_Model(Points(i), Graphics.Load));

                            P1 = Graphics.Load.Chord_Surface.A1_projected * (1 - Points(i)) + Graphics.Load.Chord_Surface.A2_projected * Points(i);
                            P2 = Graphics.Load.Chord_Surface.A3_projected * (1 - Points(i)) + Graphics.Load.Chord_Surface.A4_projected * Points(i);

                            Xd_Plot(i,:) = (P1 * (1 - k) + P2 * k)';

                        end

                    otherwise

                        for i=1:size(Points,1)

                            k = Center_Of_Mass(Access_Model_X(Points(i), Graphics.Load));

                            P1 = Graphics.Load.Chord_Surface.A1_projected * (1 - Points(i)) + Graphics.Load.Chord_Surface.A2_projected * Points(i);
                            P2 = Graphics.Load.Chord_Surface.A3_projected * (1 - Points(i)) + Graphics.Load.Chord_Surface.A4_projected * Points(i);

                            Xd_Plot(i,:) = (P1 * (1 - k) + P2 * k)';

                        end

                end

            end
            
            Pressure_Centers_Line = plot3(Axes_Handle, Xd_Plot(:,1), Xd_Plot(:,2), Xd_Plot(:,3));

            set(Pressure_Centers_Line, 'Color', Graphics_Properties.Xd_Plot_Color);
            set(Pressure_Centers_Line, 'LineWidth', Graphics_Properties.Xd_Plot_Line_Width);
            set(Pressure_Centers_Line, 'Tag', 'Pressure_Centers_Line');
            
        else
            
            delete(findall(Graphic_Window_Handle, 'Tag', 'Pressure_Centers_Line'));
            
        end
        
end
